import docx
doc = docx.Document('Word文档示例.docx')
# 使用len函数获取段落数
pnums = len(doc.paragraphs)
print(f'本文档共有{pnums}个段落')
for index, p in enumerate(doc.paragraphs):
    # 打印每个段落中的run多个数
    print(f'第{index+1}段有{len(p.runs)}个run')

print('============我们通过p.text读取段落的里的文本')
for p in doc.paragraphs:
    print(p.text)

print('============我们通过r.text读取run里的文本')
for index, p in enumerate(doc.paragraphs):
    print(f'第{index+1}段有{len(p.runs)}个run:')
    for r in p.runs:
        print(r.text)

print('============查看各种对象的类型')
print(f'doc是：{type(doc)} 类型')
print(f'doc.paragraphs是：{type(doc.paragraphs)} 类型')
print(f'paragraph是：{doc.paragraphs[0]} 类型')
print(f'paragraph.runs是：{type(doc.paragraphs[0].runs)} 类型')
print(f'run是：{type(doc.paragraphs[0].runs[0])} 类型')
